home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / grafix / 3d / iiutilities.lha / IIUtilities / Jitter < prev    next >
Encoding:
Text File  |  1995-01-18  |  3.3 KB  |  95 lines

  1. /*\
  2.  *
  3.  *  This ARexx script will randomly disturb the points in an object file.
  4.  *
  5.  *  Usage: Jitter <ObjectFileName> <X Distance> [Y Distance] [Z Distance]
  6.  *    Distance is how far to move a point in a given direction.
  7.  *    If you leave out the Y or Z sizes Jitter will duplicate the
  8.  *    previous size.  Ex. Using just one number jitter an object evenly
  9.  *    while using a large X and 1 for Y and Z would only affect points
  10.  *    along the X axis.  This is the GLOBAL axis, not the object.
  11.  *    This script will parse through grouped objects as well and do each
  12.  *    one as it finds them.  It can be a little slow for huge objects.
  13.  *  For a nice rough ground effect you can use a plane with lots of
  14.  *  subdivisions.  Play around with scaling each axis diffrently for some
  15.  *  interesting effects.
  16.  *
  17.  *  V1.0 Nov-22-94
  18.  *  IanSmith@psu.edu
  19.  *
  20. \*/
  21.  
  22. Numeric Digits 14                    /* Need at least 12 to handle 32 bits */
  23.  
  24. Parse Arg FileName Amount.X Amount.Y Amount.Z .
  25.  
  26. If Amount.X="" Then Do
  27.  Say "Usage: Jitter <ObjectFileName> <X Distance> [Y Distance] [Z Distance]"
  28.  Say "Please enter at least an X value.  More help is in this file."
  29.  Exit
  30. End
  31. If Amount.Y="" Then Amount.Y=Amount.X
  32. If Amount.Z="" Then Amount.Z=Amount.Y
  33.  
  34. If Open(In,FileName,"R")=0 Then Do
  35.  Say "ERROR: I can't open" FileName
  36.  Exit
  37. End
  38. Call Open(Out,FileName||".Out","W")
  39.  
  40. If InOut(4)~="FORM" Then Do                /* Is it a FORM? */
  41.  Say "This is not an IFF FORM file."
  42.  Exit
  43. End
  44. Size=C2D(InOut(4))
  45. Call ParseHUNK(Size,InOut(4))
  46.  
  47. Exit
  48.  
  49. ParseHUNK: PROCEDURE EXPOSE Amount.             /* Recursive function */
  50.  Parse Arg MaxSize , HunkName
  51.  TotalSize=0
  52.  Do Until TotalSize>=MaxSize
  53.   Name=InOut(4)
  54.   Size=C2D(InOut(4))
  55.   If Size//2=1 Then                             /* Pad IFF hunk if odd */
  56.    Size=Size+1
  57.   If Name="OBJ " | Name="DESC" | Name="TOBJ" | Name="ISTG" | Name="SOBJ" Then Do   /* Recurse into these hunks */
  58.    TotalSize=TotalSize+ParseHUNK(Size,Name)+8
  59.    Iterate
  60.   End
  61.   TotalSize=TotalSize+Size+8                   /* Add header size */
  62.   If Name="NAME" Then Do
  63.    ObjName=InOut(Size)
  64.   End; Else If Name="PNTS" Then Do                  /* Only parse Points */
  65.    Points=C2D(InOut(2))
  66.    Say "Jittering" ObjName "with" Points "points"
  67.    Do Pcn=1 To Points
  68.     Call WriteCH(Out,FToBin(BinToF(ReadCH(In,4))+(RandU()*Amount.X*2-Amount.X)))
  69.     Call WriteCH(Out,FToBin(BinToF(ReadCH(In,4))+(RandU()*Amount.Y*2-Amount.Y)))
  70.     Call WriteCH(Out,FToBin(BinToF(ReadCH(In,4))+(RandU()*Amount.Z*2-Amount.Z)))
  71.    End
  72.   End; Else Do
  73.    Call InOut(Size)
  74.   End
  75.  End
  76. Return TotalSize
  77.  
  78. FToBin: PROCEDURE
  79.  Parse Arg ConvertBNum                      /* Convert back to Imagine FP.  */
  80.  If ConvertBNum<0 Then                      /* D2C(2**31) is broken!        */
  81.   ConvertBNum=2**32+ConvertBNum*65536
  82.  Else
  83.   ConvertBNum=ConvertBNum*65536
  84. Return Right(D2C(ConvertBNum/65536%1),2,'00'x)||Right(D2C(ConvertBNum//65536%1),2,'00'x)
  85.  
  86. BinToF: PROCEDURE                           /* Convert from Imagine FP nums   */
  87.  Parse Arg ConvertFNum                      /* to something we can work with. */
  88. Return C2D(ConvertFNum)/65536
  89.  
  90. InOut:
  91.  Parse Arg Bytes .                          /* Read bytes, write them */
  92.  InOutData=ReadCH(In,Bytes)                 /* back out and return to */
  93.  Call WriteCH(Out,InOutData)                /* the calling function.  */
  94. Return InOutData
  95.